import jade.path.Path;
import jade.path.Path.PathFactory;
import jade.util.Coord;
import jade.util.Direction;

import java.awt.Color;

class Enemy extends Creature {
	boolean awake;

	Enemy(PrisonEscape parent, char face, Dungeon dungeon, Color color, int hp, int atk, int def,
			int dmg) {
		super(parent, face, "guard", dungeon, color, hp, atk, def, dmg);
		visionRange = 2;
		awake = true;
	}

	@Override
	public void act() {
		if (!move)
			return;
		move = false;

		Coord nextPosition;
		if (awake)
			nextPosition = getNextPosition(dungeon.getLevel().getPlayer().getPos());
		else {
			nextPosition = dungeon.getLevel().getOpenTile();

			// Remove diagonals
			if (Math.abs(nextPosition.getX() - getX()) > Math.abs(nextPosition
					.getY()
					- getY()))
				nextPosition.move(nextPosition.getX(), getY());
			else
				nextPosition.move(getX(), nextPosition.getY());
		}

		moveOrSlide(Direction.deltaToDirect(nextPosition.getX() - getX(),
				nextPosition.getY() - getY()));
	}

	private Coord getNextPosition(Coord destionation) {
		Path aStar = PathFactory.get(PathFactory.AStar);
		return aStar.getPath(dungeon.getLevel(), getPos(), destionation).get(0);
	}
}
